using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using emp.ProcessFlow;
using emp.BLL;
using emp.Model;

public partial class crm_quest_QuestionLableList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (this.tablename.Text != null)
                inital(this.tablename.Text.ToString());
            else
            {
                inital("");
            }
        }


    }

    protected void gvquestlist_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {

        GridView theGrid = sender as GridView;
        int newPageIndex = 0;
        if (-2 == e.NewPageIndex)
        {
            TextBox txtNewPageIndex = null;
            GridViewRow pagerRow = theGrid.BottomPagerRow;
            if (null != pagerRow)
            {
                txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox;
            }
            if (null != txtNewPageIndex)
            {
                newPageIndex = int.Parse(txtNewPageIndex.Text) - 1;
            }
        }
        else
        {
            newPageIndex = e.NewPageIndex;
        }

        newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
        newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex;
        theGrid.PageIndex = newPageIndex;
        inital(this.tablename.Text.Trim());
    }

    void inital(string name)
    {
        Quest quest = new Quest();
        IList questList = quest.getQuestLabelList(name);

        this.gvquestlist.DataSource = questList;
        this.gvquestlist.DataBind();       

        if (questList.Count > 0)
        {
            Label lbrecordcount = gvquestlist.BottomPagerRow.FindControl("lbrecordcount") as Label;
            lbrecordcount.Text = questList.Count.ToString();
        }

    }


    protected void serach_Click(object sender, EventArgs e)
    {
        inital(this.tablename.Text.Trim());
    }
    protected void addbutton_Click(object sender, EventArgs e)
    {
        Response.Redirect("QuestionLableAdd.aspx");
    }
}
